// pages/mine/mine.js
let { AJAX, timeTranfer,imgUrl } = require("../../utils/util.js")
const App = getApp()

Page({

   /**
    * 页面的初始数据
    */
   data: {
      info: '1',
      isAuth: true,
     imgUrl: imgUrl
   },

   /**
    * 生命周期函数--监听页面加载
    */
   onLoad: function(options) {
      if (!wx.getStorageSync("ACCESSTOKEN")) {
         App.userInfoReadyCallback = res => {
            wx.setStorageSync('ACCESSTOKEN', res);
            this.userInfo()
            this.requestAuch()
         }
         return
      }

      this.userInfo()
      this.requestAuch()
   },

   /**
    * 生命周期函数--监听页面初次渲染完成
    */
   onReady: function() {

   },

   /**
    * 生命周期函数--监听页面显示
    */
   onShow: function() {
      this.userInfo()
      this.requestAuch()
   },

   /**
    * 生命周期函数--监听页面隐藏
    */
   onHide: function() {

   },

   /**
    * 生命周期函数--监听页面卸载
    */
   onUnload: function() {

   },

   /**
    * 页面相关事件处理函数--监听用户下拉动作
    */
   onPullDownRefresh: function() {

   },

   /**
    * 页面上拉触底事件的处理函数
    */
   onReachBottom: function() {

   },

   /**
    * 用户点击右上角分享
    */
   onShareAppMessage: function() {

   },
   tolist(e) {
      let _type = e.currentTarget.dataset.type
      wx.navigateTo({
         url: '/pages/order/orderlist/orderlist?type=' + _type,
      })
   },
   toInfo(e) {
      let _path = e.currentTarget.dataset.path
      wx.navigateTo({
         url: _path,
      })
   },
   toChange() {
      wx.navigateTo({
         url: '/pages/mine/change/change',
      })
   },
   /**
    * 授权
    */
   requestAuch() {
      let vm = this
      AJAX("member/auth").then(res => {
         vm.setData({
            isAuth: res.data.auth
         })
         if (!vm.data.isAuth) {
            return wx.navigateTo({
               url: '/pages/authorization/authorization',
            })
         } else {
            wx.navigateTo({
               url: '/pages/mine/mine'
            })
         }
      })
   },

   /**
    * member/member-info
    * 判断手机号是否绑定
    */
   isBindPhone() {
      let vm = this
      AJAX("member/member-info").then(res => {
         if (res.data.mobile == null || res.data.mobile =='') {
            wx.navigateTo({
               url: '/pages/mine/backstage/bindPhone/bindPhone',
             
            })
         } else {
            wx.navigateTo({
               url: '/pages/mine/backstage/backstage',
            })
         }
      })
   },
   bankCard() {
      let vm = this
      AJAX("member/member-info").then(res => {
         console.log(res.data)
         if (res.data.mobile == null || res.data.mobile == '') {
            wx.navigateTo({
               url: '/pages/mine/backstage/bindPhone/bindPhone',
            })
         } else {
            wx.navigateTo({
               url: '/pages/mine/bankCard/bindCard',
            })
         }
      })
   },
   userInfo() {
      AJAX('member/member-info').then(res => {
         console.log(res)
         this.setData({
            info: res.data,
         })
      })
   }
})